#ifndef __SLOTHTTPD_FCGI_APPLICATION_HPP__
#define __SLOTHTTPD_FCGI_APPLICATION_HPP__

#include <slothttpd/fcgi/multiplexer.hpp>

#include <cstdint>

#include <boost/asio.hpp>

namespace slothttpd {
namespace fcgi {

class application
{
    friend class multiplexer;
public:
    typedef boost::intrusive::list<multiplexer, boost::intrusive::constant_time_size<false> > multiplexer_list;
    typedef boost::asio::local::stream_protocol::endpoint endpoint_type;
    
    // doesn't throw if copy ctors and operator= of handlers don't throw
    multiplexer::request_controller begin_request(
            receive_buffer_list *stdout, 
            receive_buffer_list *stderr, 
            multiplexer::request_id::get_write_buffer_type get_buffers,
            multiplexer::request_id::handler_type handler);
    
    void close();
    
public:
    std::uint16_t requests_per_connection; // > 0
    endpoint_type endpoint;
    
private:
    multiplexer_list full_connections;
    multiplexer_list not_full_connections;
};

}
}

#endif
